home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / pascal / soundpas.zip / WAVEPLAY.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-20  |  5KB  |  211 lines

  1. unit WavePlay;
  2.  
  3. {
  4.   WavePlay                                     
  5.   Programmer: Charlie Calvert                  
  6.   Date: March 1993                             
  7.  
  8.   Copyright (c) June 1993, by Charlie Calvert
  9.   Feel free to use this code as an adjunct to your own programs.
  10. }
  11.  
  12. interface
  13.  
  14. uses
  15.   MMSystem, Objects, ODialogs, OWindows, PlayDlg,
  16.   PlayerId, Strings, TimeName, WaveUnit, WinDos,
  17.   WinTypes, WinProcs;
  18.  
  19. const
  20.   DevStr = 'WaveAudio';
  21.  
  22. type
  23.   PWaveDlg = ^TWaveDlg;
  24.   TWaveDlg = Object(TPlayDialog)
  25.       FileBox: PListBox;
  26.       StatInfo, LenText, DevInfo, TimeLapsed: PStatic;
  27.       EdCurDir: PEdit;
  28.       TimeName: TTimeNameRec;
  29.     constructor Init(AParent: PWindowsObject; AName: PChar);
  30.     destructor Done; virtual;
  31.     procedure SetUpWindow; virtual;
  32.     procedure GetDetails;
  33.     function GetTimeAndName: Boolean;
  34.     procedure GetDirectoryInfo(var Msg: TMessage);
  35.       virtual Wm_First + Wm_FillDir;
  36.     procedure MciNotify(var Msg: TMessage);
  37.       virtual wm_First + mm_MciNotify;
  38.     procedure NewTimeName(var Msg: TMessage);
  39.       virtual wm_First + wm_TimeName;
  40.     procedure WaveAbort(var Msg: TMessage);
  41.       virtual id_First + idAbort;
  42.     procedure WavePause(var Msg: TMessage);
  43.       virtual id_First + id_WavePause;
  44.     procedure WavePlay(var Msg: TMessage);
  45.       virtual id_First + id_WavePlay;
  46.     procedure WaveFill(var Msg: TMessage);
  47.       virtual id_First + id_WaveFill;
  48.     procedure WaveRecord(var Msg: TMessage);
  49.       virtual id_First + id_WaveRecord;
  50.     procedure WmTimer(var Msg: TMessage);
  51.       virtual wm_First + Wm_Timer;
  52.   end;
  53.  
  54. implementation
  55.  
  56. constructor TWaveDlg.Init(AParent: PWindowsObject; AName: PChar);
  57. begin
  58.   inherited Init(AParent, AName);
  59.   FileBox := New(PListBox, InitResource(@Self, id_WaveList));
  60.   TimeLapsed := New(PStatic, InitResource(@Self, id_WaveNumTracks, MinLen));
  61.   StatInfo := New(PStatic, InitResource(@Self, 125, MinLen));
  62.   LenText := New(PStatic, InitResource(@Self, id_WaveLenInfo, MinLen));
  63.   DevInfo := New(PStatic, InitResource(@Self, id_WaveDevInfo, MinLen));
  64.   EdCurDir := New(PEdit, InitResource(@Self, id_WaveCurDir, MaxLen));
  65. end;
  66.  
  67. destructor TWaveDlg.Done;
  68. begin
  69.   inherited Done;
  70.   { CloseMci; }
  71. end;
  72.  
  73. procedure TWaveDlg.SetUpWindow;
  74. var
  75.   Msg: TMessage;
  76. begin
  77.   inherited SetUpWindow;
  78.   StrCopy(WildCard, '*.Wav');
  79.   GetWindowsDirectory(CurrentDirectory, MaxLen);
  80.   SetCurDir(CurrentDirectory);
  81.   PostMessage(HWindow, Wm_FillDir, 0, 0);
  82. end;
  83.  
  84. procedure TWaveDlg.GetDetails;
  85. var
  86.   S: array[0..MinLen] Of Char;
  87.   Result: LongInt;
  88. begin
  89.   Result := GetLen;
  90.   wvsPrintf(S, '%ld ms', Result);
  91.   LenText^.SetText(S);
  92.   Str(GetLocation, S);
  93.   TimeLapsed^.SetText(S);
  94.   DevInfo^.SetText(GetInfo(S));
  95. end;
  96.  
  97. procedure TWaveDlg.GetDirectoryInfo(var Msg: TMessage);
  98. var
  99.   S: array[0..15] of Char;
  100. begin
  101.   SetCurDir(CurrentDirectory);
  102.   StrCopy(S, '*.wav');
  103.   if FileBox^.GetCount > 0 then FileBox^.ClearList;
  104.   SendMessage(FileBox^.HWindow, LB_DIR, DDL_ARCHIVE, LongInt(@S));
  105.   FileBox^.SetSelIndex(0);
  106.   EdCurDir^.SetText(CurrentDirectory);
  107. end;
  108.  
  109. procedure TWaveDlg.MciNotify(var Msg: TMessage);
  110. begin
  111.   GetDetails;
  112.   Case Mode of
  113.     Mci_Mode_Record: begin
  114.       StatInfo^.SetText('Stopped');
  115.       if (MessageBox(HWindow, 'Save file?', 'Question?',
  116.                 mb_YesNo or mb_IconQuestion) = idYes) then
  117.       SaveFile(TimeName.FileName);
  118.       CloseMci;
  119.       Mode := Mci_Mode_Stop;
  120.     end;
  121.   else
  122.     CloseMci;
  123.   end;
  124.   KillTimer(HWindow, PlayTimer);
  125. end;
  126.  
  127. procedure TWaveDlg.WaveAbort(var Msg: TMessage);
  128. begin
  129.   CloseMci;
  130. end;
  131.  
  132. procedure TWaveDlg.WavePlay(var Msg: TMessage);
  133. var
  134.   S1,
  135.   Buf: array [0..MaxLen] of Char;
  136. begin
  137.   if (FileBox^.GetSelString(Buf, MaxLen) < 0) then begin
  138.     MessageBox(HWindow, 'No file selected in listbox', '', mb_Ok);
  139.     exit;
  140.   end;
  141.   StrCopy(S1, CurrentDirectory);
  142.   StrCat(S1, '\');
  143.   StrCat(S1, Buf);
  144.   OpenMci(HWindow, S1, DevStr);
  145.   SetTimeFormatMS;
  146.   GetDetails;
  147.   PlayMci;
  148.   StartTimer;
  149. end;
  150.  
  151. procedure TWaveDlg.WavePause(var Msg: TMessage);
  152. begin
  153. end;
  154.  
  155. procedure TWaveDlg.WaveFill(var Msg: TMessage);
  156. var
  157.   S: array[0..MaxLen] of Char;
  158.   i: Integer;
  159. begin
  160.   EdCurDir^.GetText(S, MaxLen);
  161.   StrCopy(CurrentDirectory, S);
  162.   SendMessage(HWindow, WM_FillDir, 0, 0);
  163. end;
  164.  
  165. procedure TWaveDlg.NewTimeName(var Msg: TMessage);
  166. begin
  167.   Move(PTimeNameRec(Msg.LParam)^, TimeName, SizeOf(TTimeNameRec));
  168. end;
  169.  
  170. function TWaveDlg.GetTimeAndName: Boolean;
  171. var
  172.   D: PTimeNameDlg;
  173. begin
  174.   GetTimeAndName := True;
  175.   StrCopy(TimeName.FileName, 'Foobar.Wav');
  176.   D := New(PTimeNameDlg, Init(@Self, 'TimeName', TimeName));
  177.   if Application^.ExecDialog(D) = idCancel then
  178.     GetTimeAndName := False;
  179. end;
  180.  
  181. procedure TWaveDlg.WaveRecord(var Msg: TMessage);
  182. var
  183.   Len: Word;
  184.   S: array[0..MaxLen] of Char;
  185. begin
  186.   if not GetTimeAndName then Exit;
  187.   if not OpenMci(HWindow, '', DevStr) then Exit;
  188.   StatInfo^.SetText('Record');
  189.   Len := TimeName.Time * 1000;
  190.   wvsprintf(S, '%d', Len);
  191.   LenText^.SetText(S);
  192.   Mode := Mci_Mode_Record;
  193.   SetTimeFormatMS;
  194.   DoRecord(Len);
  195.   StartTimer;
  196.   Exit;
  197.   StatInfo^.SetText('Stopped');
  198.   if (MessageBox(HWindow, 'Save file?', 'Question?',
  199.                 mb_YesNo or mb_IconQuestion) = idYes) then
  200.     SaveFile(TimeName.FileName);
  201.   CloseMci;
  202. end;
  203.  
  204. procedure TWaveDlg.WmTimer(var Msg: TMessage);
  205. begin
  206.   GetDetails;
  207. end;
  208. end.
  209.  
  210.  
  211.